# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)



# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

FILE ( GLOB_RECURSE	lame_sources lame/*.c )
LIST ( SORT			lame_sources )

#INCLUDE_DIRECTORIES("lame")
#INCLUDE_DIRECTORIES(".")

FILE ( GLOB_RECURSE	fdk_aac_sources "fdk-aac/*.cpp" )
LIST ( SORT			fdk_aac_sources )


set(fdk_aac_sources_list ${fdk_aac_sources})
#message(WARNING "fdk_aac_sources_list 1111 ${fdk_aac_sources_list}")
list(REMOVE_ITEM fdk_aac_sources_list "${CMAKE_CURRENT_SOURCE_DIR}/fdk-aac/libAACdec/src/arm/block_arm.cpp")
list(REMOVE_ITEM fdk_aac_sources_list "${CMAKE_CURRENT_SOURCE_DIR}/fdk-aac/libFDK/src/arm/dct_arm.cpp")
list(REMOVE_ITEM fdk_aac_sources_list "${CMAKE_CURRENT_SOURCE_DIR}/fdk-aac/libFDK/src/arm/fft_rad2_arm.cpp")
list(REMOVE_ITEM fdk_aac_sources_list "${CMAKE_CURRENT_SOURCE_DIR}/fdk-aac/libFDK/src/mips/fft_rad2_mips.cpp")
list(REMOVE_ITEM fdk_aac_sources_list "${CMAKE_CURRENT_SOURCE_DIR}/fdk-aac/libFDK/src/arm/scale_arm.cpp")
list(REMOVE_ITEM fdk_aac_sources_list "${CMAKE_CURRENT_SOURCE_DIR}/fdk-aac/libFDK/src/mips/scale_mips.cpp")
list(REMOVE_ITEM fdk_aac_sources_list "${CMAKE_CURRENT_SOURCE_DIR}/fdk-aac/libFDK/src/mips/mips_fft_twiddles.cpp")
list(REMOVE_ITEM fdk_aac_sources_list "${CMAKE_CURRENT_SOURCE_DIR}/fdk-aac/libSBRdec/src/arm/lpp_tran_arm.cpp")
#message(WARNING "fdk_aac_sources_list 2222 ${fdk_aac_sources_list}")

INCLUDE_DIRECTORIES("fdk-aac/libAACdec/include")
INCLUDE_DIRECTORIES("fdk-aac/libAACdec/src")
INCLUDE_DIRECTORIES("fdk-aac/libDRCdec/include")
INCLUDE_DIRECTORIES("fdk-aac/libDRCdec/src")
INCLUDE_DIRECTORIES("fdk-aac/libMpegTPEnc/include")
INCLUDE_DIRECTORIES("fdk-aac/libMpegTPEnc/src")
INCLUDE_DIRECTORIES("fdk-aac/libSACenc/include")
INCLUDE_DIRECTORIES("fdk-aac/libSACenc/src")
INCLUDE_DIRECTORIES("fdk-aac/libSYS/include")
INCLUDE_DIRECTORIES("fdk-aac/libSYS/src")
INCLUDE_DIRECTORIES("fdk-aac/libAACenc/include")
INCLUDE_DIRECTORIES("fdk-aac/libAACenc/src")
INCLUDE_DIRECTORIES("fdk-aac/libFDK/include/arm")
INCLUDE_DIRECTORIES("fdk-aac/libFDK/include")
INCLUDE_DIRECTORIES("fdk-aac/libFDK/src")
INCLUDE_DIRECTORIES("fdk-aac/libPCMutils/include")
INCLUDE_DIRECTORIES("fdk-aac/libPCMutils/src")
INCLUDE_DIRECTORIES("fdk-aac/libSBRdec/include")
INCLUDE_DIRECTORIES("fdk-aac/libSBRdec/src")
INCLUDE_DIRECTORIES("fdk-aac/libArithCoding/include")
INCLUDE_DIRECTORIES("fdk-aac/libArithCoding/src")
INCLUDE_DIRECTORIES("fdk-aac/libMpegTPDec/include")
INCLUDE_DIRECTORIES("fdk-aac/libMpegTPDec/src")
INCLUDE_DIRECTORIES("fdk-aac/libSACdec/include")
INCLUDE_DIRECTORIES("fdk-aac/libSACdec/src")
INCLUDE_DIRECTORIES("fdk-aac/libSBRenc/include")
INCLUDE_DIRECTORIES("fdk-aac/libSBRenc/src")
INCLUDE_DIRECTORIES("fdk-aac/libAACdec/include")
INCLUDE_DIRECTORIES("fdk-aac/libAACdec/src")

#ADD_DEFINITIONS(
#        -O3 -g -W -Wall -Wno-unused-parameter -Wno-#warnings
#        -Wuninitialized -Wno-self-assign
#)

#ADD_DEFINITIONS(
#        -O3 -g -W -Wall
#        -Wunused-variable -Wunused-parameter -Wunused-function -Wunused
#        -Wno-deprecated -Woverloaded-virtual -Wwrite-strings
#        -D__WUR= -D_REENTRANT -D_FILE_OFFSET_BITS=64 -DTIXML_USE_STL
#)

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
	     mp3_encode.cpp
             native-lib.cpp
             ${lame_sources}
             ${fdk_aac_sources_list}	     
	     
	      )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )